package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.SystemLog;
import cn.wolfcode.crm.mapper.SystemLogMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.support.RequestContextUtils;

import java.util.Date;

public class SystemLogUtil {
    @Autowired
    private SystemLogMapper systemLogMapper;

    /**
     * 系统日志
     * @param joinPoint
     */
    public void wirtrLog(JoinPoint joinPoint) {
        /*String function = joinPoint.getTarget().getClass().getName()+":" + joinPoint.getSignature().getName();
        if(function.contains("select")||function.contains("importXls")||
                function.contains("login")||
                function.contains("get")||
                function.contains("list")||
                function.contains("query")){
            return;
        }
        SystemLog systemLog = new SystemLog();
        systemLog.setOpTime(new Date());
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        systemLog.setOpUser(employee.getUsername());
        systemLog.setFunction(function);
        systemLog.setOplp(RequestUtil.getRequest().getRemoteAddr());
        try {
            Object[] args = joinPoint.getArgs();
            systemLog.setParams(new ObjectMapper().writeValueAsString(args));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        systemLogMapper.insert(systemLog);*/
    }
}
